package cn.appsys.controller.deve;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.appsys.constants.Constants;
import cn.appsys.pojo.DevUser;
import cn.appsys.service.deve.DevUserService;

@Controller
@RequestMapping("/dev/login")
public class DevLoginController {
	@Resource
	private DevUserService devUserService;
	//登录跳转
	@RequestMapping("/toLogin")
	public String toLogin(@RequestParam("devCode")String devCode ,
							@RequestParam("devPassword")String devPassword,
							HttpSession session,Model model){
		DevUser devUser = devUserService.userDevLogin(devCode);
		if(devUser == null) {
			model.addAttribute("error", "没有该用户");
			return"devlogin";
		}else if(!devUser.getDevPassword().equals(devPassword)) {
			model.addAttribute("error", "密码不正确");
			return"devlogin";
		}else {
			session.setAttribute(Constants.DEV_USER_SESSION, devUser);
			return"developer/main";
		}
	}
	@RequestMapping("/devlogin")
	public String devlogin() {
		return "devlogin";
	}
}
